from django.db import models

# Create your models here.
from django.db import models


class Projects(models.Model):
    project_name = models.CharField(max_length=200)
    project_tag = models.CharField(max_length=500)
    project_icon = models.CharField(max_length=100)
    project_desp = models.CharField(max_length=4096)

    def __str__(self):
        return self.project_name


class SimpleScripts(models.Model):
    script_name = models.CharField(max_length=100)
    script_version = models.CharField(max_length=20)
    script_time = models.DateTimeField()
    script_path = models.CharField(max_length=1024)
    script_interface = models.CharField(max_length=200)
    script_url = models.CharField(max_length=256)
    script_desp = models.CharField(max_length=1024)
    project = models.ForeignKey(Projects, on_delete=models.CASCADE)

    def __str__(self):
        return self.script_name


class SimpleScriptsLog(models.Model):
    script = models.ForeignKey(SimpleScripts, on_delete=models.CASCADE)
    start_time = models.DateTimeField()
    end_time = models.DateTimeField()
    result_type = models.IntegerField()
    result_path = models.CharField(max_length=1024)
    result_error = models.CharField(max_length=4096)
    time_cost = models.IntegerField()

    def __str__(self):
        return self.script.script_name


class ComplexScripts(models.Model):
    script_name = models.CharField(max_length=100)
    script_version = models.CharField(max_length=20)
    script_time = models.DateTimeField()
    script_path = models.CharField(max_length=1024)
    script_url = models.CharField(max_length=256)
    script_desp = models.CharField(max_length=1024)
    script_requirements = models.CharField(max_length=4096)

    def __str__(self):
        return self.script_name


class ComplexScriptsLog(models.Model):
    start_time = models.DateTimeField()
    end_time = models.DateTimeField()
    result_type = models.IntegerField()
    result_path = models.CharField(max_length=1024)
    result_error = models.CharField(max_length=4096)
    time_cost = models.IntegerField()


class Task(models.Model):
    task_name = models.CharField(max_length=100)
    task_corn = models.CharField(max_length=10)
    task_script_type = models.IntegerField()
    task_script_id = models.IntegerField()

    def __str__(self):
        return self.task_name


class TaskLog(models.Model):
    task_start_time = models.DateTimeField()
    task_end_time = models.DateTimeField()
    task_log = models.CharField(max_length=4096)
    task = models.ForeignKey(Task, on_delete=models.CASCADE)


class TaskStatics(models.Model):
    success_times = models.IntegerField()
    error_times = models.IntegerField()
    success_cost_time = models.BigIntegerField()
    error_cost_time = models.BigIntegerField()
    task = models.ForeignKey(Task, on_delete=models.CASCADE)


class DeviceInfo(models.Model):
    device_id = models.CharField(max_length=100)
    device_name = models.CharField(max_length=100, null=True)
    device_type = models.IntegerField()

    def __str__(self):
        return self.device_name
